package org.mineground.commands.player;

import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.mineground.Main;

/**
 * @file mainWorld.java (01.03.2012)
 * @author Daniel Koenen
 *
 */
public class MainWorld implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender cs, Command cmnd, String string, String[] arguments) {
        Player player = (Player) cs;
        World mainWorld = Main.getInstance().getServer().getWorld(Main.getInstance().getConfigHandler().mainWorldName);
        
        if (mainWorld == null) {
            player.sendMessage(ChatColor.RED + "* Error: That world is not supported right now, please contact an administrator.");
            return true;
        }
        
        if (mainWorld == player.getWorld()) {
            player.sendMessage(ChatColor.RED + "* Error: You are already in the main world.");
            return true;
        }
        
        if (player.getWorld() == Main.getInstance().getServer().getWorld(Main.getInstance().getConfigHandler().survivalWorldName)) {
            Main.getInstance().getPlayer(player).initializeSurvivalMovementDelay(mainWorld.getSpawnLocation());
            return true;
        }
        
        player.sendMessage(ChatColor.DARK_GREEN + "Welcome to the main world!");
        player.teleport(mainWorld.getSpawnLocation());
        return true;
    }
}
